﻿using K4os.Hash.xxHash;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zhaoxi.SqlSugar.Models;

namespace Zhaoxi.SqlSugarAdvanced.SaasSubDatabase
{
    /// <summary>
    /// Saas分库案例实操
    /// </summary>
    public class OrderManger : DbManger
    {
        /// <summary>
        /// Saas分库案例实操
        /// </summary>
        public void Test()
        {

            OrderHead orderHead = new OrderHead()
            {
                CreateTime = DateTime.Now,
                Id = 1,
                Name = "测试数据",
                Price = 345
            };
            OrderItemNew orderItemNew1 = new OrderItemNew()
            {
                CreateTime = DateTime.Now,
                Price = 399,
                OrderId = 1,
                Description = "测试数据"
            };

            try
            {
                Db.BeginTran();//用Db管理 MasterDb和BizDb事务 支持跨库事务  
                MasterDb.Insertable(orderHead).ExecuteCommand();//操作基础信息库
                BizDb.Insertable(orderItemNew1).ExecuteCommand();//操作业务库  
                Db.CommitTran();//统一事务 
            }
            catch (Exception)
            {
                Db.RollbackTran();
            };
        }
    }
}
